/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 62536
 * Date: 2024-06-16
 * Time: 9:59
 */
public class Solution {
    public int minCost(int[][] costs) {
        int m = costs.length;
        int[][] dp = new int[m][3];
        System.arraycopy(costs[0], 0, dp[0], 0, 3);
        for (int i = 1; i < m; i++) {
            for (int j = 0; j < 3; j++) {
                if(j == 0){
                    dp[i][j] = Math.min(dp[i-1][1], dp[i-1][2]) + costs[i][j];
                } else if (j == 1){
                    dp[i][j] = Math.min(dp[i-1][0], dp[i-1][2]) + costs[i][j];
                } else {
                    dp[i][j] = Math.min(dp[i-1][0], dp[i-1][1]) + costs[i][j];
                }
            }
        }

        return Math.min(dp[m-1][0], Math.min(dp[m-1][1], dp[m-1][2]));

    }
}
